package org.example.blog.service;

import org.example.blog.mapper.BlogInfoMapper;
import org.example.blog.mapper.UserInfoMapper;
import org.example.blog.model.BlogInfo;
import org.example.blog.model.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {

    @Autowired
    private UserInfoMapper userInfoMapper;

    @Autowired
    private BlogInfoMapper blogInfoMapper;
    public UserInfo queryByName(String name) {
        return userInfoMapper.queryByName(name);
    }

    public UserInfo queryById(Integer userId) {
        return userInfoMapper.queryById(userId);
    }

    //1. 根据blogId 获取博客详情 进而获取userId
    //2. 根据userid 获取userInfo
    public UserInfo getAuthorInfo(Integer blogId) {
        BlogInfo blogInfo = blogInfoMapper.queryById(blogId);
        if (blogInfo == null || blogInfo.getUserId() < 0) {
            return null;
        }
        return userInfoMapper.queryById(blogInfo.getUserId());
    }
}
